package com.trex.lwlsh.test;

import org.apache.commons.codec.digest.DigestUtils;
import java.util.Date;

/**
 * Create by Trex on 2018/1/23
 */
public class bizToken {
    private final static String TOKEN_SEPERATOR = "_";

    public static void main(String[] args) {
        createToken();
    }

    private static void createToken() {
        String t = String.valueOf((new Date()).getTime());
        String appId = "website";

        // 测试appId
        String testAppkey = "passwd11343432455432532452";
        //印尼appid
//        String testAppkey = "passwd11343432455432532452";
        // 生产appId
        //String appkey = "5dd1ad1701dda79f43fb1e742e54a6e2";
        String appkey = "ca6cee3288d043ef2f57bdb498ab4224";
        // String appkey = "5dd1ad1701dda79f43fb1e742e54a6e2";
        String tetToken = computeToken(t, appId, testAppkey);
        String token = computeToken(t, appId, appkey);
        System.out.println("TEST:appId=website&t="+t+"&token="+tetToken);
        System.out.println("PRODUCE:appId=website&t="+t+"&token="+token);
    }

    private static String computeToken(String t, String appId, String appkey) {
        String str =appId + TOKEN_SEPERATOR + appkey + TOKEN_SEPERATOR + t;
        System.out.println("str="+str);
        return md5Hex(appId + TOKEN_SEPERATOR + appkey + TOKEN_SEPERATOR + t);
    }

    private static String md5Hex(String data) {
        return DigestUtils.md5Hex(data).toLowerCase();
    }
}
